# ExpoBase

My personal bot base.<br/>
Not the best, but it works.

Uses Esbuild for both dev and prod.

Written entirely from scratch in TypeScript.

## Mongo

### Setup

You *will* need a mongodb instance for it to properly work without modification. Making it work without one should be relatively easy; simply remove things like auth etc...

To get a mongodb instance running, see [this gist](https://gist.github.com/Exponential-Workload/be6575f73b57eb6dd4aef5daccd1ef6c).

To get a non-persistent db (ie for a bot that doesnt have any db-required functionality for those too lazy to change shit), remove `docker volume create mangodata` from install.sh, and remove
```yml
volumes:
  mangodata:
    external: true
```
from your docker compose.

### Storage

In mongodb, the last command's hash is stored, alongside all users that have permissions (or other metadata).

### Permissions

#### Initially obtaining

To gain bot-wide priveleges (such as eval), you need an account that has the developer permission node. If your DB is fresh (as it likely will be at some point), you won't be able to use /lookup-user to modify your own permissions. Instead, temporarily set the env var `FORCE_CREATE_USER` to your user id and restart the bot - this will forcefully create a user when you run a command. Before closing the bot, run any command as this user.

After that, enable `managePermissions`. Note that you can only grant others permissions you have, unless you are also given the `developer` permission. This permission, aswell as the group with the same name, is usually reserved for dangerous actions.

#### Modifying

Once you have the `developer` or `managePermissions` permission, you can use `/lookup-user` to find a user's permissions (and other db info), and `/set-user-perm <user> <permission> <value>` to modify a user's permissions.

> Warning:
> You can revoke your own permissions.

#### Adding Permissions

Permissions are stored in `src/util/db/perms.ts`. You can add more there.

## Logging

Logs are outputted to stdout, by default at a level of `INFO`, however that's changable via the `LOG_LEVEL` env var.

Additionally, logs are outputted to `logs/latest.log` (last log is moved to `logs/last.log` on start) at `INFO` (or higher, if `LOG_LEVEL` is higher - e.g. if `LOG_LEVEL` is `warn`, it will only include warnings). 

Finally, warnings and errors are always emitted to `logs/error.log`. This file will not be reset unless removed.

## Licensing

If you use this base, you must provide attribution to the original. Additionally, your fork must be open source unless an exception has been granted to you, in writing (inclusive digital writing), by Expo. You must follow all of the terms, excluding if an aforementioned exception is provided, of the AGPL-3.0, or at your discression, any later version, when using this base.
